/*
 Copyright 2008 Under Dusken

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

package org.dyndns.anderlin.jmplayer.model;

import org.apache.log4j.Logger;
import org.springframework.binding.value.support.AbstractPropertyChangePublisher;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Calendar;

@MappedSuperclass
public abstract class JmplayerObject extends AbstractPropertyChangePublisher
        implements Serializable {

    protected static final Logger log = Logger.getLogger(JmplayerObject.class);

    /**
     * The unique Identifier
     */
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    protected Long ID;

    /**
     * The identifier given by the external source, if any
     */
    @Basic(optional = true)
    @Column(name = "externalid")
    protected Long externalID;

    /**
     * The time this entity was imported, if it ever was
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    protected Calendar imported;

    @Version
    protected Integer version;

    public JmplayerObject(Long ID) {
        this.ID = ID;
    }

    public JmplayerObject() {
        // needed for jpa
    }

    public Long getID() {
        return this.ID;
    }

    public void setID(Long ID) {
        Long oldID = this.ID;
        this.ID = ID;
        firePropertyChange("ID", oldID, ID);
    }

    public Long getExternalID() {
        return externalID;
    }

    public void setExternalID(Long externalID) {
        Long oldExternalID = this.externalID;
        this.externalID = externalID;
        firePropertyChange("externalID", oldExternalID, externalID);
    }

    public Calendar getImported() {
        return imported;
    }

    public void setImported(Calendar imported) {
        Calendar oldImported = this.imported;
        this.imported = imported;
        firePropertyChange("imported", oldImported, imported);
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        Integer oldVersion = this.version;
        this.version = version;
        firePropertyChange("version", oldVersion, version);
    }
}
